CLASS zcl_moon_zapi DEFINITION
  PUBLIC
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_http_service_extension .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_MOON_ZAPI IMPLEMENTATION.


  METHOD if_http_service_extension~handle_request.
    CONSTANTS:if_system_class_prefix TYPE c LENGTH 8 VALUE 'ZCL_MES_',
              if_method              TYPE c LENGTH 4 VALUE 'POST'.


    DATA:lv_req TYPE string,
         lv_res TYPE string.
    DATA:ptab TYPE abap_parmbind_tab,
         etab TYPE abap_excpbind_tab.


    lv_req = request->get_text( ).
    DATA(if_name) = request->get_form_field('IF_NAME').
    DATA(if_class_name) = if_system_class_prefix && if_name.

    ptab = VALUE #( ( name  = 'REQUEST'
                      kind  = cl_abap_objectdescr=>exporting
                      value = REF #( lv_req ) )
                    ( name  = 'RESPONSE'
                      kind  = cl_abap_objectdescr=>importing
                      value = REF #( lv_res ) ) ).

    CALL METHOD (if_class_name)=>(if_method)
      PARAMETER-TABLE
      ptab.

    response->set_header_field(
      EXPORTING
        i_name  = 'content-type'
        i_value = 'application/json'
    ).
    response->set_text( lv_res ).
  ENDMETHOD.
ENDCLASS.
